package outoforder.leetcode01;

import outoforder.leetcode.TreeNode;

/**
 * @author shhjiang_001
 * @create 2020-07-10 16:59
 */
// 完全二叉树的个数
public class Solution222 {
    public int countNodes(TreeNode root) {
        TreeNode l = root;
        TreeNode r = root;
        int hl = 0,hr = 0;
        while (l != null){
            hl++;
            l = l.left;
        }
        while (r != null){
            hr++;
            r = r.right;
        }
        if (hl == hr){
            return (int) Math.pow(2,hl)-1;
        }

        return 1+countNodes(root.left)+countNodes(root.right);
    }
}
